using System;
using System.Collections;
using System.Text;
using RedGate.SQLDataGenerator.Engine.Generators;
using RedGate.SQLDataGenerator.Engine.Generators.Static;
using RedGate.SQLDataGenerator.Engine.Generators.Support;

namespace SimpleTalk.WaffleGenerator
{
    [Generator(typeof(string), "Generic", "Waffle Generator", "Creates quantities of Waffle")]
    [Matches(".*Html.*", 10)]
    [Matches(".*Text.*", 10)]
    public class WaffleGenerator : GeneratorBase
    {
        private int m_Paragraphs = 10;
        private Boolean m_HTML = true;
        private Boolean m_Headings = true;

        public int Paragraphs
        {
            get { return m_Paragraphs; }
            set
            {
                if(m_Paragraphs < 0)
                {
                    throw new ArgumentException("You must specify a positive number of Paragraphs");
                }
                m_Paragraphs = value;
            }
        }
        public Boolean HTML
        {
            get { return m_HTML; }
            set
             {
            m_HTML=value;
        }
        }
        public Boolean Headings
        {
            get { return m_Headings; }
            set
            {
                m_Headings = value;
            }

        }
       
        public WaffleGenerator(GeneratorParameters parameters) : base(parameters)
        {
        }

        public override IEnumerator GetNonNullEnumerator(GenerationSession session)
        {
            Random r = new Random(m_Seed);
            StringBuilder sb = new StringBuilder();
            WaffleEngine we = new WaffleEngine(r);

            if (m_HTML)
            {
                while (true)
                {
                    we.HtmlWaffle(m_Paragraphs, m_Headings, sb);
                    yield return sb.ToString();
                    sb.Length = 0;
                }
            }
            else
            {
                while (true)
                {
                    we.TextWaffle(m_Paragraphs, m_Headings, sb);
                    yield return sb.ToString();
                    sb.Length = 0;
                }
            }
        }
    }
}
